<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../../../views/include/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>新增服务包关系</title>
<head>
    <meta charset="utf-8">
    <title>新增服务包关系</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">

    <link rel="stylesheet" href="/fdoctor-ms/statics/beginnerAdmin/plugins/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/fdoctor-ms/statics/beginnerAdmin/plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/fdoctor-ms/statics/beginnerAdmin/css/btable.css" />
    
    <script type="text/javascript" src="/fdoctor-ms/statics/beginnerAdmin/plugins/layui/layui.js"></script>
    <script type="text/javascript" src="/fdoctor-ms/statics/js/jquery-2.1.4.min.js"></script>
    <script type="text/javascript" src="/fdoctor-ms/statics/js/inputTools.js"></script>
    
</head>

<body>
	<fieldset class="layui-elem-field layui-field-title" style="margin-top: 5px;margin-left: 5px;margin-right: 5px">
	  <legend>新增服务包关系
	  </legend>
	</fieldset>
	<form class="layui-form" action="" id="dataForm">
	<input type=hidden name="updateMan" id="updateMan" value="${sessionScope.user_in_session.userName}"/>
	<input type=hidden name="sigId" id="sigId" value="${id}"/>
		<div class="layui-inline"  >
			  	<label class="layui-form-label" > 选择服务项目：</label>
			    <div class="layui-input-inline" ">
			      	<select name="detailId" id="detailId" lay-search lay-filter="detailId">
						<option value="" style="width: 190px;">可输入服务项目名搜索</option>
							<c:forEach items="${detailAll}" var="detailItem">
								<option value="${detailItem.id}">${detailItem.serviceName}</option>
							</c:forEach>
					</select>  
			    </div>
			  	</div>
		<div class="layui-form-item" style="width: 90%">
			<label class="layui-form-label">服务描述：</label>
			<div class="layui-input-block">
		       <textarea type="" class="layui-textarea" name="serviceDetails" id="serviceDetails" readOnly="true"></textarea>
		    </div>
		</div>
		
		<div class="layui-form-item" style="width: 90%">
			<label class="layui-form-label">服务频率</label>
			<div class="layui-input-block">
		      <input name="frequency"  class="layui-input"  id="frequency" readOnly="true">
		    </div>
		</div>  
		
		<hr>
	  <div align="center">
	  		<button class="layui-btn layui-btn-big layui-btn-primary layui-btn-radius" type="button" id="saveButton"><i class="layui-icon">&#xe618;</i>确认保存</button>
	  </div>
	</form>
	  
</body>

<script type="text/javascript">
	//初始化表单控件
layui.use(['jquery', 'form','laydate'], function() {
	$ = layui.jquery;
	form = layui.form();
	var laydate = layui.laydate;
	
	form.on('select(detailId)', function(data) {
		var detailList=${detailAll2};
		for(i=0;i<detailList.length;i++){
			if(data.value==detailList[i].id){
				$('#serviceDetails').text(detailList[i].serviceDetails);
				if(frequency==-1){
					$('#frequency').val("不限次数");
				}else{
					$('#frequency').val("一年"+detailList[i].frequency+"次");
				}
				break;
			}
		}
		form.render;
	})
	
	
    $('#saveButton').on('click',function(){
    	if($('#detailId').val() == null || $('#detailId').val() ==''){
    		layer.msg('请选择服务项目！',{icon: 7});
    		return;
    	}
    	
    	
    	layer.confirm('确认在该服务包和服务项目间建立对于关系？', {icon: 3, title:'提示'}, function(index){
			layer.close(index);
			$.ajax({
				type : 'POST',
				url : '/fdoctor-ms/servicePack/saveRelation',
				data : packParams(),
				success : function(data) {
					if (data.code == 200) {
						var index = parent.layer.getFrameIndex(window.name);
						parent.layer.close(index);
						parent.layer.msg('保存成功！', {
							icon : 1
						});
						parent.tableConfig();
					} else {
						parent.layer.msg('保存失败！', {
							icon : 2
						});
					}
				}
			});
		});
    });
    
    function packParams(){
    	var param = {
				sigId:$('#sigId').val(),
				detailId:$('#detailId').val()
		}
		return param;
	}
    
   
})
</script>
</html>